package com.hqj.controller;

import com.hqj.dao.AgreementDao;
import com.hqj.entity.Agreement;
import com.hqj.service.AgreementServiceI;
import com.hqj.util.ReturnValueUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/agc")
public class AgreementController extends  BaseController<Agreement> {
    @Resource(name="agreementServiceI")
    private AgreementServiceI asi;


    @Override
    public String index() {
        return "pages/agreement/index";
    }

    @Override
    public String addEdit(HttpServletRequest req, Model model) {
        String id = req.getParameter("id");
        if(id!=null){
            Agreement agreement = new Agreement();
            agreement.setId(Integer.parseInt(id));
            agreement = asi.get(agreement);
            model.addAttribute("agr",agreement);
            return "pages/agreement/check";
        }
        long agreementId = System.currentTimeMillis();
        model.addAttribute("agreementId",agreementId);
        return "pages/agreement/add";
    }

    @Override
    public String find(Agreement agreement) {
        List<Agreement> list = asi.find(agreement);
        return ReturnValueUtil.findData(list.size(),list);
    }

    @Override
    public Map<String, Object> add(Agreement agreement) {
        return asi.add(agreement);
    }
}
